class Solution {
public:
    int countCompleteSubarrays(vector<int>& nums) {
        int cnt=0,ret=0;
        unordered_set<int> has;
        for(int i=0;i<nums.size();i++)
        {
            has.insert(nums[i]);
        }
        cnt=has.size();
        has.clear();
        unordered_map<int,int> h;
        int left=0,right=0;
        while(right<nums.size())
        {
            h[nums[right]]++;
            while(h.size()==cnt)
            {
                int cur=nums[left];
                if(--h[nums[left]]==0)
                {
                    h.erase(nums[left]);
                }
                left++;
            }
            ret+=left;
            right++;
        }

        return ret;
    }
};
